package bsc.war.ajax;

import bsc.ejb.entity.Person;
import bsc.ejb.entity.PersonScoreDomain;
import bsc.ejb.entity.ScoreDomain;
import bsc.ejb.entity.ScoreView;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author castrosalazr
 */
public class DesignerAddUser extends AbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        try {

            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");
            String type = request.getParameter("type");

            Person.Profile profiles[] = Person.Profile.values();
            Person _person = "edit".equals(type) && NumberUtils.isDigits(request.getParameter("id")) ? delegate.findPerson(Long.valueOf(request.getParameter("id"))) : null;

            request.setAttribute("edit", "edit".equals(type));
            request.setAttribute("profiles", profiles);
            request.setAttribute("_person", _person);

        } catch (Exception e) {
            e.printStackTrace();
        }

        return new ModelAndView("designerAddUser");
    }
}